namespace Example.Models
{
    using System.Xml;
    using System.Xml.Serialization;
    using SimpleWebServices.Data;
    using SimpleWebServices.Models;

    [XmlRoot("contact")]
    public sealed class Contact : Record
    {
        public Contact()
            : this(null as FormSession)
        {
        }

        public Contact(FormSession session)
        {
            if (null != session)
            {
                this.Choice = XmlConvert.ToInt32(session.Data["choice"] ?? "0");
                this.Email = session.Data["email"];
                this.Name = session.Data["name"];
                this.Message = session.Data["message"];
                this.TermsAndConditions = session.Data.Contains("terms_and_conditions");
            }
        }

        [XmlAttribute("choice")]
        public int Choice
        {
            get;
            set;
        }

        [XmlAttribute("email")]
        public string Email
        {
            get;
            set;
        }

        [XmlIgnore]
        public override string Entity
        {
            get
            {
                Entity value = new Entity();
                value.Append(this.Choice);
                value.Append(this.Email);
                value.Append(this.Message);
                value.Append(this.Name);
                value.Append(this.TermsAndConditions);

                return value;
            }
        }

        [XmlElement("message")]
        public string Message
        {
            get;
            set;
        }

        [XmlAttribute("name")]
        public string Name
        {
            get;
            set;
        }

        [XmlAttribute("terms_and_conditions")]
        public bool TermsAndConditions
        {
            get;
            set;
        }
    }
}